package org.graduates.webapp.actions.course.json;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.graduates.webapp.actions.BaseAction;
import org.projects.graduates.domain.Teaching;
import org.projects.graduates.page.Pager;

import com.opensymphony.xwork2.ActionSupport;

@ParentPackage("web")
public class WantStudySearchAction extends BaseAction {
	private static final long serialVersionUID = 4545648531129699383L;

	private List<Teaching> teaches = new ArrayList<Teaching>();

	private long currentPage = 1;

	private long total = 1;

	private long pageSize = 10;

	private String search;

	@Action(results = { @Result(name = "success", type = "json", params = {
			"includeProperties",
			"total, pageSize, pageNumber,search," + "teaches,teaches\\[\\d+\\]\\.id,teaches\\[\\d+\\]\\.course,teaches\\[\\d+\\]\\.course.id," + "teaches\\[\\d+\\]\\.course.name," + "teaches\\[\\d+\\]\\.course.enable, "
					+ "teaches\\[\\d+\\]\\.course.tag, " + "teaches\\[\\d+\\]\\.person,teaches\\[\\d+\\]\\.person.id," + "teaches\\[\\d+\\]\\.person.showName" }) })
	public String execute() {

		if ("lasts".equals(search)) {
			Pager pager = Teaching.pagerOfAll(getCurrentPersonId(), currentPage, pageSize);
			total = pager.getRowCount();
			teaches.addAll(Teaching.theLasts(currentPage, pageSize, getCurrentPerson()));
		}

		return ActionSupport.SUCCESS;
	}

	public List<Teaching> getTeaches() {
		return teaches;
	}

	public void setTeaches(List<Teaching> teaches) {
		this.teaches = teaches;
	}

	public String getSearch() {
		return search;
	}

	public void setSearch(String search) {
		this.search = search;
	}

	public long getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(long currentPage) {
		this.currentPage = currentPage;
	}

	public long getTotal() {
		return total;
	}

	public void setTotal(long total) {
		this.total = total;
	}

	public long getPageSize() {
		return pageSize;
	}

	public void setPageSize(long pageSize) {
		this.pageSize = pageSize;
	}

}
